package com.lagou.dao;

import com.lagou.domain.Employee;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 员工表dao层接口
 */
public interface EmployeeDao {
    //查询所有
    @Select("SELECT e.emp_id," +
            "e.emp_name," +
            "e.dept_id," +
            "t.dept_name," +
            "e.job_name," +
            "e.join_date," +
            "e.telephone " +
            "FROM employee e , department t WHERE e.dept_id = t.dept_id;")
    public List<Employee> findAll();

    //新增
    @Insert("INSERT INTO employee VALUES" +
           "(NULL,#{emp_name},#{dept_id},#{job_name},#{join_date},#{telephone});")
    public int save(Employee employee);

    //根据id查询
    @Select("SELECT e.emp_id," +
            "e.emp_name," +
            "e.dept_id," +
            "t.dept_name," +
            "e.job_name," +
            "e.join_date," +
            "e.telephone " +
            "FROM employee e , department t WHERE e.dept_id = t.dept_id and e.emp_id = #{id};")
    public Employee findById(Integer id);

    //更新
    @Update("update employee set emp_name = #{emp_name}," +
            "dept_id = #{dept_id}," +
            "job_name = #{job_name}," +
            "join_date = #{join_date}," +
            "telephone = #{telephone}" +
            "where emp_id = #{emp_id}")
    public void update(Employee employee);
}
